<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class StatisticsAttend extends AdminController {

	function __construct() {
		parent::__construct();
		$this-> load->model('Attend_model');
		$this-> load->model('Attend_teaching_readiness_model');
		$this-> load->model('Attend_students_norm_model');
		$this-> load->model('Table1_model');
	}

	function Index($teacher_code='',$listen_name=''){
		$data['listen_code'] = urldecode($teacher_code);
		$data['listen_name'] = urldecode($listen_name);
		$this->load->view('admin/statisticsAttendList',$data);
	}

	function getDatas($params = array(), $isExport = false){
		$connar = array();
		if (!$isExport) {
			$params = $_POST;
			$connar = $this -> Attend_model -> pickPages($connar, $params);
		}
		// $connar['items']='listen_id,usercode,username';
		// $connar['where']=$this->sqlEscape('db_attend.status=??',array(AttendStatus::Submit[XPHEnum::Value]));
		// $connar['join']=array('db_admin','db_admin.id=db_attend.listen_id');
		// $connar['groupby']='listen_id';
		$where='where db_attend.status='.AttendStatus::Submit[XPHEnum::Value];
		$role=explode(',',getSess()['sub_role_id']);
		array_push($role,getSess()['role_id']);
		// foreach ($role as $k => $v) {
		// 	if($v==WebRole::UnitSupervisor[XPHEnum::Value] ||$v==WebRole::SchoolSupervisor[XPHEnum::Value] || $v==WebRole::ExternalSupervisor[XPHEnum::Value] || $v==WebRole::SupervisorDirector[XPHEnum::Value]){
		// 		$where.=' and db_admin.id='.getSess()['id'];
		// 	}else if($v==WebRole::UnitSupervisorGroupLeader[XPHEnum::Value]){
		// 		$where.=' and (dept_id='.getSess()['dept_id'].' or db_admin.id='.getSess()['id'].')';
		// 	}else if($v==WebRole::Manage[XPHEnum::Value]){
		// 		// $connar['where'].=$this->sqlEscape(' and admin_type=??',array(AdminType::Auth[XPHEnum::Value]));
		// 	}
		// }
	if(in_array(WebRole::Manage[XPHEnum::Value], $role)){
			$where.=' and 1=1';
		}else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) && in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			$where.=' and dept_id='.getSess()['dept_id'].' and if(db_admin.id='.getSess()['id'].',1=1,(type='.AttendType::Unit[XPHEnum::Value].' or type='.AttendType::Outside[XPHEnum::Value].'))';
	}else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) && !in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			$where.=' and dept_id='.getSess()['dept_id'].' and (db_attend.type='.AttendType::Unit[XPHEnum::Value].' and db_attend.type='.AttendType::Outside[XPHEnum::Value].')';		
		}else if(in_array(WebRole::UnitSupervisor[XPHEnum::Value], $role)){
			$where.=' and db_admin.id='.getSess()['id'];		
		}else if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role)){

		}else if(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			$where.=' and db_admin.id='.getSess()['id'];
		}else if(in_array(WebRole::ExternalSupervisor[XPHEnum::Value], $role)){
			$where.=' and db_admin.id='.getSess()['id'];
		}else if(in_array(WebRole::SupervisorDirector[XPHEnum::Value], $role)){
			$where.=' and db_admin.id='.getSess()['id'];
		}else if(in_array(WebRole::OutsideSupervisor[XPHEnum::Value], $role)){
			$where.=' and db_admin.id='.getSess()['id'];
		}

		if (isset($params['start_time']) && isset($params['end_time'])) {
			$where.=' and db_attend.listen_time>'.strtotime($params['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
		}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
			$where.=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
		}

		if (isset($params['dept_name'])) {
			$where.=' and db_admin.dept_name like "%'.$params['dept_name'].'%"';
		}else if (isset($_POST['dept_name'])) {
			$where.=' and db_attend.dept_name like "%'.$_POST['dept_name'].'%"';
		}
		if (isset($params['username'])) {
			$where.=' and db_admin.username like "%'.$params['username'].'%"';
		}else if (isset($_POST['username'])) {
			$where.=' and db_admin.username like "%'.$_POST['username'].'%"';
		}
		if (isset($params['level']) && $params['level']!=-1) {
			if($params['level']==FeedBackSubType::School[XPHEnum::Value]){
				$level=WebRole::SchoolSupervisor[XPHEnum::Value];
			}
			if($params['level']==FeedBackSubType::Unit[XPHEnum::Value]){
				$level=WebRole::UnitSupervisor[XPHEnum::Value];
			}
			$where.=' and (role_id='.$level.' or find_in_set('.$level.',sub_role_id))';
		}else if (isset($_POST['level']) && $_POST['level']!=-1) {
			if($_POST['level']==FeedBackSubType::School[XPHEnum::Value]){
				$level=WebRole::SchoolSupervisor[XPHEnum::Value];
			}
			if($_POST['level']==FeedBackSubType::Unit[XPHEnum::Value]){
				$level=WebRole::UnitSupervisor[XPHEnum::Value];
			}
			$where.=' and (role_id='.$level.' or find_in_set('.$level.',sub_role_id))';
		}

		if(isset($params['content'])){
			$where.=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
		}else if (isset($_POST['content'])) {
			$where.=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
		}
		if(!$isExport){
			if(isset($params['pageNo']) && isset($params['pageSize'])){			
				$pageNo=$_POST['pageNo']-1;
				$pageSize=$_POST['pageSize'];
			}else{
				$pageNo='0';
				$pageSize='20';
			}
		}		
		if (!$isExport) {
			$data = $this -> Attend_model -> get_page_list($connar);
			$data['ret']=$this -> Attend_model->query('select * from(select listen_id,usercode,username from db_attend left join db_admin on db_admin.id=db_attend.listen_id left join db_attend_record on db_attend.id=db_attend_record.attend_id '.$where.') attend group by listen_id'.' limit '.$pageSize*$pageNo.','.$pageSize);
			$count=$this -> Attend_model -> query('select count(*) count from(select count(*) count from(select listen_id,usercode,username from db_attend left join db_admin on db_admin.id=db_attend.listen_id left join db_attend_record on db_attend.id=db_attend_record.attend_id '.$where.') attend group by listen_id)a ');
			$data['count']=$count[0]['count'];
			$data['totalPage']=ceil($data['count']/$pageSize);
		} else {
			$data['ret']=$this -> Attend_model->query('select * from(select listen_id,usercode,username from db_attend left join db_admin on db_admin.id=db_attend.listen_id left join db_attend_record on db_attend.id=db_attend_record.attend_id '.$where.') attend group by listen_id');
			$count=$this -> Attend_model -> query('select count(*) count from(select count(*) count from(select listen_id,usercode,username from db_attend left join db_admin on db_admin.id=db_attend.listen_id left join db_attend_record on db_attend.id=db_attend_record.attend_id '.$where.') attend group by listen_id)a');
		}

		foreach ($data['ret'] as $k => $v) {
			// 以督导身份听课人数
			$connarnum['items']='count(DISTINCT teacher_name) attend_num';
			$connarnum['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
			$connarnum['join'][0]=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			$connarnum['join'][1]=array('db_admin','db_admin.id=db_attend.listen_id');
			if(isset($params['content'])){
				$connarnum['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connarnum['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connarnum['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			if (isset($params['dept_name'])  && $params['dept_name']!='') {
				$connarnum['where'].=$this->sqlLikeEscape(' and db_admin.dept_name like "%??%"',array($params['dept_name']));
			}else if (isset($_POST['dept_name']) && $_POST['dept_name']!='') {
				$connarnum['where'].=$this->sqlLikeEscape(' and db_attend.dept_name like "%??%"',array($_POST['dept_name']));
			}
			if (isset($params['username'])   && $params['username']!='') {
				$connarnum['where'].=$this->sqlLikeEscape(' and db_admin.username like "%??%"',array($params['username']));
			}else if (isset($_POST['username'])   && $_POST['username']!='') {
				$connarnum['where'].=$this->sqlLikeEscape(' and db_admin.username like "%??%"',array($_POST['username']));
			}

			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) && in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	$connar['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }
			
			// $connar['groupby']='teacher_name';
			
			$num=$this->Attend_model->get_single_full($connarnum);
			$data['ret'][$k]['attend_num']=$num['attend_num'];
			// 以督导身份听课次数
			$connar1['items']='COUNT(*) attend_count';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
			$connar1['join'][0]=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			$connar1['join'][1]=array('db_admin','db_admin.id=db_attend.listen_id');
			if(isset($params['content'])){
				$connar1['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			if (isset($params['dept_name']) && $params['dept_name']!='') {
				$connar1['where'].=$this->sqlEscape(' and db_admin.dept_name like "%??%"',array($params['dept_name']));
			}else if (isset($_POST['dept_name']) && $_POST['dept_name']!='') {
				$connar1['where'].=$this->sqlEscape(' and db_attend.dept_name like "%??%"',array($_POST['dept_name']));
			}
			if (isset($params['username'])&& $params['username']!='') {
				$connar1['where'].=$this->sqlLikeEscape(' and db_admin.username like "%??%"',array($params['username']));
			}else if (isset($_POST['username'])&& $_POST['username']!='') {
				$connar1['where'].=$this->sqlLikeEscape(' and db_admin.username like "%??%"',array($_POST['username']));
			}
			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) && in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	$connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }
			$count=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['attend_count']=$count['attend_count'];

			// 以校督导身份听课人数
			$connarnum['items']='count(DISTINCT teacher_name) attend_num';
			$connarnum['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
			$connarnum['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connarnum['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connarnum['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connarnum['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			
			$num=$this->Attend_model->get_single_full($connarnum);
			$data['ret'][$k]['attend_school_num']=$num['attend_num'];
			// 以校督导身份听课次数
			$connar1['items']='COUNT(*) attend_count';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
			$connar1['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar1['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			$count=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['attend_school_count']=$count['attend_count'];

			// 以外聘督导身份听课人数
			$connarnum['items']='count(DISTINCT teacher_name) attend_num';
			$connarnum['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
			$connarnum['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connarnum['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connarnum['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connarnum['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			
			$num=$this->Attend_model->get_single_full($connarnum);
			$data['ret'][$k]['attend_outside_num']=$num['attend_num'];

			// 以外聘督导身份听课次数
			$connar1['items']='COUNT(*) attend_count';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=??',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
			$connar1['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar1['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			$count=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['attend_outside_count']=$count['attend_count'];

			//总平均分
			$connar1['items']='avg(score) avg';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? ',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value]));
			$connar['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role)){
			// 	$connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }else(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	 $connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::School[XPHEnum::Value]));
			// }
			$avg_level=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['avg_total_score']=sprintf("%.2f",$avg_level['avg']);

				//校督导听课平均分
			$connar1['items']='avg(score) avg';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=?? ',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::School[XPHEnum::Value]));
			$connar['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role)){
			// 	$connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }else(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	 $connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::School[XPHEnum::Value]));
			// }
			$avg_level=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['avg_school_score']=sprintf("%.2f",$avg_level['avg']);


		//e二级督导听课平均分
			$connar1['items']='avg(score) avg';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=?? ',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Unit[XPHEnum::Value]));
			$connar['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role)){
			// 	$connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }else(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	 $connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::School[XPHEnum::Value]));
			// }
			$avg_level=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['avg_unit_score']=sprintf("%.2f",$avg_level['avg']);


					//外聘督导听课平均分
			$connar1['items']='avg(score) avg';
			$connar1['where']=$this->sqlEscape('listen_id=?? and db_attend.status=?? and type=?? ',array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],AttendType::Outside[XPHEnum::Value]));
			$connar['join']=array('db_attend_record','db_attend_record.attend_id=db_attend.id');
			if(isset($params['content'])){
				$connar['where'].=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$connar1['where'].=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$connar1['where'].=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			// if(in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitSupervisorGroupLeader[XPHEnum::Value], $role)){
			// 	$connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::Unit[XPHEnum::Value]));
			// }else(in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)){
			// 	 $connar1['where'].=$this->sqlEscape(' and type=??',array(AttendType::School[XPHEnum::Value]));
			// }
			$avg_level=$this->Attend_model->get_single_full($connar1);
			$data['ret'][$k]['avg_outside_score']=sprintf("%.2f",$avg_level['avg']);

			// 总分最高分
			
			if (isset($params['start_time']) && isset($params['end_time'])) {
				$where=$this->sqlEscape(' and db_attend.listen_time>??  and db_attend.listen_time<??',array(strtotime($params['start_time'].' 00:00:00'),strtotime($_POST['end_time']." 23:59:59")));
			}else if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$where=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}else{
				$where='';
			}
			if(isset($_POST['content'])){
				$where.=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($_POST['dept_name'])) {
				$where.=' and db_attend.dept_name like "%'.$_POST['dept_name'].'%"';
			}
			if (isset($_POST['username'])) {
				$where.=' and db_admin.username like "%'.$_POST['username'].'%"';
			}
			if (isset($_POST['level']) && $_POST['level']!=-1) {
				if($_POST['level']==FeedBackSubType::School[XPHEnum::Value]){
					$level=WebRole::SchoolSupervisor[XPHEnum::Value];
				}
				if($_POST['level']==FeedBackSubType::Unit[XPHEnum::Value]){
					$level=WebRole::UnitSupervisor[XPHEnum::Value];
				}
				$where.=' and (role_id='.$level.' or find_in_set('.$level.',sub_role_id))';
			}

			
			$sql=$this->sqlEscape("select * from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id where score=(SELECT max(score) from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where listen_id=??  and db_attend.status=?? ".$where." ) and listen_id=??  and db_attend.status=?? ".$where." group by teacher_name",array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],$v['listen_id'],AttendStatus::Submit[XPHEnum::Value]));
			$max=$this->Attend_model->query($sql);
			$max_score=$max[0]['score'];
			$max_teacher_name=implode(',', array_column($max,'teacher_name'));
			$data['ret'][$k]['max_score']=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';


			// 总分最低分
			$sql=$this->sqlEscape("select * from db_attend left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where score=(SELECT min(score)  from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id where listen_id=??  and db_attend.status=?? ".$where." ) and listen_id=??  and db_attend.status=?? ".$where." group by teacher_name",array($v['listen_id'],AttendStatus::Submit[XPHEnum::Value],$v['listen_id'],AttendStatus::Submit[XPHEnum::Value]));
			$min=$this->Attend_model->query($sql);
			$min_score=$min[0]['score'];
			$min_teacher_name=implode(',', array_column($min,'teacher_name'));
			$data['ret'][$k]['min_score']=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';

			$data['ret'][$k]['num']=$k+1;

		}
		
		if (!$isExport) {

			$attend_num_unit=0;
			$attend_count_unit=0;
			$attend_num_school=0;
			$attend_count_school=0;
			$attend_num_outside=0;
			$attend_count_outside=0;
			$avg_total_score=0;
			$avg_school_score=0;
			$avg_unit_score=0;
			$avg_outside_score=0;

			foreach ($data['ret'] as $k => $v) {
				$attend_num_unit+=$v['attend_num'];
				$attend_count_unit+=$v['attend_count'];
				$attend_num_school+=$v['attend_school_num'];
				$attend_count_school+=$v['attend_school_count'];

				$attend_num_outside+=$v['attend_outside_num'];
				$attend_count_outside+=$v['attend_outside_count'];

				$avg_total_score+=$v['avg_total_score'];
				$avg_school_score+=$v['avg_school_score'];
				$avg_unit_score+=$v['avg_unit_score'];
				$avg_outside_score+=$v['avg_outside_score'];

			}

			$count = count($data['ret']);

			$data['ret'][$count]['username']= '合计';
			$data['ret'][$count]['attend_num']=$attend_num_unit;
			$data['ret'][$count]['attend_count']=$attend_count_unit;
			$data['ret'][$count]['attend_school_num']=$attend_num_school;
			$data['ret'][$count]['attend_school_count']=$attend_count_school;
			$data['ret'][$count]['attend_outside_num']=$attend_num_outside;
			$data['ret'][$count]['attend_outside_count']=$attend_count_outside;
			$data['ret'][$count]['avg_total_score']=$avg_total_score;
			$data['ret'][$count]['avg_school_score']=$avg_school_score;
			$data['ret'][$count]['avg_unit_score']=$avg_unit_score;
			$data['ret'][$count]['avg_outside_score']=$avg_outside_score;
			$data['ret'][$count]['max_score']='';
			$data['ret'][$count]['min_score']='';

			if(count($data['ret'])!=0){

			// 总分最高分			
			$where=" and 1=1";
			if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$where.=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			if(isset($_POST['content'])){
				$where.=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($_POST['dept_name'])) {
				$where.=' and db_attend.dept_name like "%'.$_POST['dept_name'].'%"';
			}
			if (isset($_POST['username'])) {
				$where.=' and db_admin.username like "%'.$_POST['username'].'%"';
			}
			if (isset($_POST['level']) && $_POST['level']!=-1) {
				if($_POST['level']==FeedBackSubType::School[XPHEnum::Value]){
					$level=WebRole::SchoolSupervisor[XPHEnum::Value];
				}
				if($_POST['level']==FeedBackSubType::Unit[XPHEnum::Value]){
					$level=WebRole::UnitSupervisor[XPHEnum::Value];
				}
				$where.=' and (role_id='.$level.' or find_in_set('.$level.',sub_role_id))';
			}
			$sql=$this->sqlEscape("select * from db_attend left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id where score=(SELECT max(score) from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where db_attend.status=?? ".$where." ) and db_attend.status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
			$max=$this->Attend_model->query($sql);	
			if($max){
				$max_score=$max[0]['score'];
				$max_teacher_name=implode(',', array_column($max,'teacher_name'));
				$max_level=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';
			}else{
				$max_level = '';
			}		
				
			$sql=$this->sqlEscape("select * from db_attend left join db_attend_record on db_attend_record.attend_id=db_attend.id   left join db_admin on db_admin.id=db_attend.listen_id where score=(SELECT min(score) from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where db_attend.status=?? ".$where." ) and db_attend.status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
			$min=$this->Attend_model->query($sql);		

			if($min){
				$min_score=$min[0]['score'];
			    $min_teacher_name=implode(',', array_column($min,'teacher_name'));
		    	$min_level=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';
			}else{
				$min_level= '';
			}			
			
			$data['ret'][$count]['max_score']=$max_level;
			$data['ret'][$count]['min_score']=$min_level;
		}
			//echo $count; exit;

			

			echo json_encode($data);
		} else {
			// return $data["ret"];

			// 合计
			$attend_num_unit=0;
			$attend_count_unit=0;
			$attend_num_school=0;
			$attend_count_school=0;
			$attend_num_outside=0;
			$attend_count_outside=0;
			$avg_total_score=0;
			$avg_school_score=0;
			$avg_unit_score=0;
			$avg_outside_score=0;

			foreach ($data['ret'] as $k => $v) {
				$attend_num_unit+=$v['attend_num'];
				$attend_count_unit+=$v['attend_count'];
				$attend_num_school+=$v['attend_school_num'];
				$attend_count_school+=$v['attend_school_count'];

				$attend_num_outside+=$v['attend_outside_num'];
				$attend_count_outside+=$v['attend_outside_count'];

				$avg_total_score+=$v['avg_total_score'];
				$avg_school_score+=$v['avg_school_score'];
				$avg_unit_score+=$v['avg_unit_score'];
				$avg_outside_score+=$v['avg_outside_score'];

			}	


			if(count($data['ret'])!=0){

			// 总分最高分			
			$where=" and 1=1";
			if (isset($_POST['start_time']) && isset($_POST['end_time'])) {
				$where.=' and db_attend.listen_time>'.strtotime($_POST['start_time'].' 00:00:00').' and db_attend.listen_time<'.strtotime($_POST['end_time']." 23:59:59");
			}
			if(isset($_POST['content'])){
				$where.=' and db_attend_record.commentary like "%'.$_POST['content'].'%"';
			}
			if (isset($_POST['dept_name'])) {
				$where.=' and db_attend.dept_name like "%'.$_POST['dept_name'].'%"';
			}
			if (isset($_POST['username'])) {
				$where.=' and db_admin.username like "%'.$_POST['username'].'%"';
			}
			if (isset($_POST['level']) && $_POST['level']!=-1) {
				if($_POST['level']==FeedBackSubType::School[XPHEnum::Value]){
					$level=WebRole::SchoolSupervisor[XPHEnum::Value];
				}
				if($_POST['level']==FeedBackSubType::Unit[XPHEnum::Value]){
					$level=WebRole::UnitSupervisor[XPHEnum::Value];
				}
				$where.=' and (role_id='.$level.' or find_in_set('.$level.',sub_role_id))';
			}
			$sql=$this->sqlEscape("select * from db_attend left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id where score=(SELECT max(score) from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where db_attend.status=?? ".$where." ) and db_attend.status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
			$max=$this->Attend_model->query($sql);			
			$max_score=$max[0]['score'];
			$max_teacher_name=implode(',', array_column($max,'teacher_name'));
			$max_level=sprintf("%.2f",$max_score).'('.$max_teacher_name.')';

		
			$sql=$this->sqlEscape("select * from db_attend left join db_attend_record on db_attend_record.attend_id=db_attend.id   left join db_admin on db_admin.id=db_attend.listen_id where score=(SELECT min(score) from db_attend  left join db_attend_record on db_attend_record.attend_id=db_attend.id left join db_admin on db_admin.id=db_attend.listen_id  where db_attend.status=?? ".$where." ) and db_attend.status=?? ".$where." group by teacher_name",array(AttendStatus::Submit[XPHEnum::Value],AttendStatus::Submit[XPHEnum::Value]));
			$min=$this->Attend_model->query($sql);			
			$min_score=$min[0]['score'];
			$min_teacher_name=implode(',', array_column($min,'teacher_name'));
			$min_level=sprintf("%.2f",$min_score).'('.$min_teacher_name.')';

			array_push($data['ret'],array('num'=>'合计','usercode'=>'','username'=>'','attend_num'=>$attend_num_unit,'attend_count'=>$attend_count_unit,'attend_school_num'=>$attend_num_school,'attend_school_count'=>$attend_count_school,'attend_outside_num'=>$attend_num_outside,'attend_outside_count'=>$attend_count_outside,'avg_total_score'=>$avg_total_score,'avg_school_score'=>$avg_school_score,'avg_unit_score'=>$avg_unit_score,'avg_outside_score'=>$avg_outside_score,'max_score'=>$max_level,'min_score'=>$min_level));

		}else{
			array_push($data['ret'],array('num'=>'合计','usercode'=>'','username'=>'','attend_num'=>'','attend_count'=>'','attend_school_num'=>'','attend_school_count'=>'','attend_outside_num'=>'','attend_outside_count'=>'','avg_total_score'=>'','avg_school_score'=>'','avg_unit_score'=>'','avg_outside_score'=>'','max_score'=>'','min_score'=>''));
		}

		$this-> load ->library('PHPExcel/PHPExcel');
		$excel = new PHPExcel();
	        //公共样式
		$excel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(11); 
		$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setWrapText(true);
		$excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(23);
		$excel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$excel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

		$x_line=0;
		$y_line=1;

			//标题
		// $title=array($_POST['start_time'].'至'.$_POST['end_time'],'工号','姓名','督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','教学水平平均分','教学效果平均分','教学水平90分(含)以上','教学水平80以下','教学效果90分(含)以上','教学效果80以下','教学水平最高分','教学水平最低分','教学效果最高分','教学效果最低分');
		$title=array($_POST['start_time'].'至'.$_POST['end_time'],'工号','姓名','督导听课人数','督导听课次数','校督导听课人数','校督导听课次数','外聘督导听课人数','外聘督导听课次数','总分平均分','校督导平均分','二级督导平均分','外聘督导平均分','总分最高分','总分最低分');

		foreach ($title as $k => $v) {
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line,$v);
			$excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($x_line).$y_line)->getFont()->setBold(true);   
			$x_line++;
		}

		//pri($data['ret']);exit;

		$x_line=0;
		$y_line=2;
	        //正式数据
		$count=count($data['ret']);
		$num=0;
		foreach ($data['ret'] as $k => $v) {
			$num++;	 
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0).$y_line,$v['num']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(1).$y_line,$v['usercode']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(2).$y_line,$v['username']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(3).$y_line,$v['attend_num']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(4).$y_line,$v['attend_count']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(5).$y_line,$v['attend_school_num']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(6).$y_line,$v['attend_school_count']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(7).$y_line,$v['attend_outside_num']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(8).$y_line,$v['attend_outside_count']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(9).$y_line,$v['avg_total_score']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(10).$y_line,$v['avg_school_score']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(11).$y_line,$v['avg_unit_score']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(12).$y_line,$v['avg_outside_score']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(13).$y_line,$v['max_score']);
			$excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(14).$y_line,$v['min_score']);
			$y_line++;
		}

		$write = new PHPExcel_Writer_Excel2007($excel); 
		$director = "upload/export/" . date('Ymd', time()) . "/";
		if (!file_exists($director)) {
	            //检查是否有该文件夹，如果没有就创建，并给予最高权限
			mkdir($director, 0777);
		}        
		$file_name ='个人听课统计报表'.date('Ymd').'.xlsx';       	
		$write->save($director.iconv('utf-8', 'gb2312', $file_name));
		exit(retJson('返回地址',true,$director.$file_name));
	}
}

function showDetail($dept_id=false,$start_time,$end_time,$isExport=false){		
	if(!$dept_id){
		$result['dept_list']=$this ->Admin_model->query('select distinct dept_id,dept_name from db_admin where dept_id is not null');	
		$role=explode(',',getSess()['sub_role_id']);
		array_push($role,getSess()['role_id']);

		if(in_array(WebRole::Admin[XPHEnum::Value], $role)  || in_array(WebRole::Manage[XPHEnum::Value], $role) || in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) ){
		}else{
			$dept_id=getSess()['dept_id'];
		}
	}
	$params= array('start_time'=>$start_time,'end_time'=>$end_time,'dept_id'=>$dept_id);			
	$result['start_time']=$start_time;
	$result['end_time']=$end_time;


	//校督导		
	//人数
	$count['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::SchoolSupervisor[XPHEnum::Value],WebRole::SchoolSupervisor[XPHEnum::Value]));
	$count['groupby']='db_attend.listen_id';
	$count['items']='count(*) count';
	$count['join']=array('db_admin','db_admin.id=db_attend.listen_id');
	$CountSchoolSupervisor=$this -> Attend_model -> get_list_full($count);
	if($CountSchoolSupervisor){
		$result['CountSchoolSupervisor']=$CountSchoolSupervisor[0]['count'];
	}else{
		$result['CountSchoolSupervisor']=0;
	}
	//次数
	$count['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::SchoolSupervisor[XPHEnum::Value],WebRole::SchoolSupervisor[XPHEnum::Value]));
	$count['items']='count(*) count';
	$count['join']=array('db_admin','db_admin.id=db_attend.listen_id');
	$CountAttend=$this -> Attend_model -> get_list_full($count);
	if($CountAttend){
		$result['CountSchoolSupervisorSum']=$CountAttend[0]['count'];
	}else{
		$result['CountSchoolSupervisorSum']=0;
	}


	$connar['items']='db_attend.*,environmental.attend_id,environmental.option environmental_option,
	environmental.check_value environmental_check_value,facilities.option facilities_option,facilities.check_value facilities_check_vlaue ';		
	$connar['join'][0]=array('db_attend_classroom_environmental environmental','environmental.attend_id=db_attend.id');
	$connar['join'][1]=array('db_attend_classroom_facilities facilities','facilities.attend_id=db_attend.id');	
	$connar['join'][2]=array('db_admin','db_admin.id=db_attend.listen_id');
	$connar['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::SchoolSupervisor[XPHEnum::Value],WebRole::SchoolSupervisor[XPHEnum::Value]));	
	$data=$this -> Attend_model ->get_list_full($connar);

	$count=0;
	$teaching_level_score_sum=0;
	$teaching_level_A=0;
	$teaching_level_B=0;
	$teaching_effect_score_sum=0;
	$teaching_effect_A=0;
	$teaching_effect_B=0;
	$noLateEarly=0;
	$noblackboard=0;
	$siteteaching=0;
	$student_lateorleave=false;
	$student_sleep=false;
	$student_playphone=false;
	$havequestionTwo=false;
	$havequestionThree=false;
	$advice='';
	$table1show='';
	$array_advice=array();

	// 教师教学准备、开展情况	


	foreach ($data as $k => $v) {
		$late=0;
		$leave_early=0;
		$unCourseware=0;
		$unHandout=0;
		$count++;
		//教学水平
		$teaching_level_score_sum+=$v['teaching_level_score'];
		if($v['teaching_level_score']>=90){
			$teaching_level_A++;
		}else{
			$teaching_level_B++;
		}
		//教学效果
		$teaching_effect_score_sum+=$v['teaching_level_score'];
		if($v['teaching_level_score']>=90){
			$teaching_effect_A++;
		}else{
			$teaching_effect_B++;
		}
		$readine['where']=$this ->sqlEscape('attend_id=??',array($v['id']));
		$readiness=$this -> Attend_teaching_readiness_model -> get_list_full($readine);
		// var_dump($readiness);
		if($readiness){	
				foreach ($readiness as $k1 => $v1) {
					// 无迟到
					if($v1['item']==TeachingReadiness::Seventh[XPHEnum::Caption]){
						if($v1['check_value']==TeachingReadiness::Seventh[XPHEnum::Remark][1]){
							$late++;
						}
					}
					// 无早退
					if($v1['item']==TeachingReadiness::Eighth[XPHEnum::Caption] ){
						if($v1['check_value']==TeachingReadiness::Eighth[XPHEnum::Remark][1]){
							$leave_early++;				
						}
					}
					if($v1['item']==TeachingReadiness::Fifth[XPHEnum::Caption] || $v1['item']==TeachingReadiness::Sixth[XPHEnum::Caption]){
						if($v1['check_value']==TeachingReadiness::Fifth[XPHEnum::Remark][1]){
							$unCourseware++;
						}else if($v1['check_value']==TeachingReadiness::Sixth[XPHEnum::Remark][1]){
							$unHandout++;
						}
					}
					// 无板书
					if($v1['item']==TeachingReadiness::Tenth[XPHEnum::Caption]){
						if($v1['check_value']==TeachingReadiness::Tenth[XPHEnum::Remark][1]){
							$noblackboard++;
							$havequestionTwo=true;
						}
					}
					// 坐姿教学
					if($v1['item']==TeachingReadiness::Eleventh[XPHEnum::Caption]){
						if($v1['check_value']==TeachingReadiness::Eleventh[XPHEnum::Remark][1]){
							$siteteaching++;
							$havequestionTwo=true;
						}
					}
				}

				$student_n['where']=$this -> sqlEscape('attend_id=??',array($v['id']));
				$student_norm=$this -> Attend_students_norm_model -> get_list_full($student_n);
				foreach ($student_norm as $k1=> $v1) {
					// 课堂上迟到、早退2人及以上
					if($v1['item']==StudentsNorm::Fifth[XPHEnum::Caption]){
						if($v1['check_value']>='2'){
							$student_lateorleave=true;
						}
					}
					// 睡觉2人及以上
					if($v1['item']==StudentsNorm::Sixth[XPHEnum::Caption]){
						if($v1['check_value']>='2'){
							$student_sleep=true;
						}
					}
					// 玩手机5人及以上的予以点出
					if($v1['item']==StudentsNorm::Ninth[XPHEnum::Caption]){
						if($v1['check_value']>='5'){
							$student_playphone=true;
						}
					}
				}
				if($student_lateorleave || $student_sleep ||$student_playphone){
					$havequestionThree=true;
				}

				if($readiness[6]['check_value']==TeachingReadiness::Seventh[XPHEnum::Remark][1] && $readiness[7]['check_value']==TeachingReadiness::Eighth[XPHEnum::Remark][1]){
					$noLateEarly++;
				}
				$advice_num=$k+1;
				$advice=$advice.$advice_num.'.'.$v['advice'].'<br>';
				array_push($array_advice,$v['advice']);
		}
	}
	// 专题调研
	$table1['where']=$this ->sqlEscape('db_table1.status=?? and db_table1.created>?? and db_table1.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(CommonStatus::UnDeleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::SchoolSupervisor[XPHEnum::Value],WebRole::SchoolSupervisor[XPHEnum::Value]));
	$table1['join']=array('db_admin','db_admin.id=db_table1.admin_id');
	$table1['items']='db_admin.username,db_table1.title';
	$table1_data=$this -> Table1_model->get_list_full($table1);

	$table_length=count($table1_data);
	foreach ($table1_data as $k1 => $v1) {
		$table1show=$table1show.$v1['username'].'老师开展'.$v1['title'].'专题调研';

	}

	if($teaching_level_score_sum!=0 && $count!=0){
		$result['teaching_level_score_avg']=sprintf("%.2f",(intval($teaching_level_score_sum)/$count));
	}else{
		$result['teaching_level_score_avg']=0;
	}

	$result['teaching_level_A']=$teaching_level_A;
	$result['teaching_level_B']=$teaching_level_B;
	if($teaching_level_A!=0 && $count!=0){
		$result['teaching_level_Aavg']=sprintf("%.2f",($teaching_level_A/$count))*100;
	}else{
		$result['teaching_level_Aavg']=0;
	}
	if($teaching_level_B!=0 && $count!=0){
		$result['teaching_level_Bavg']=sprintf("%.2f",($teaching_level_B/$count))*100;
	}else{
		$result['teaching_level_Bavg']=0;
	}
	if($teaching_effect_score_sum!=0 && $count!=0){
		$result['teaching_effect_score_avg']=sprintf("%.2f",($teaching_effect_score_sum/$count));
	}else{
		$result['teaching_effect_score_avg']=0;
	}	

	$result['teaching_effect_A']=$teaching_effect_A;
	$result['teaching_effect_B']=$teaching_effect_B;
	if($teaching_effect_A!=0 && $count!=0){
		$result['teaching_effect_Aavg']=sprintf("%.2f",($teaching_effect_A/$count))*100;
	}else{
		$result['teaching_effect_Aavg']=0;
	}

	if($teaching_effect_B!=0 && $count!=0){
		$result['teaching_effect_Bavg']=sprintf("%.2f",($teaching_effect_B/$count))*100;
	}else{
		$result['teaching_effect_Bavg']=0;
	}


	if(!isset($late)){
		$result['late']=0;
	}
	if(!isset($leave_early)){
		$result['leave_early']=0;
	}

	$result['noLateEarly']=$noLateEarly;

	if(!isset($unCourseware)){
		$result['unCourseware']=0;
	}else{
		$result['unCourseware']=$unCourseware;
	}
	if(!isset($unHandout)){
		$result['unHandout']=0;
	}else{
		$result['unHandout']=$unHandout;
	}

	if($noblackboard==0){
		$result['noblackboard']=0;
	}else{
		$result['noblackboard']=$noblackboard;
	}
	if($siteteaching==0){
		$result['siteteaching']=0;
	}else{
		$result['siteteaching']=$siteteaching;
	}
	if($student_lateorleave==0){
		$result['student_lateorleave']=0;
	}else{
		$result['student_lateorleave']=$student_lateorleave;
	}
	if($student_sleep==0){
		$result['student_sleep']=0;
	}else{
		$result['student_sleep']=$student_sleep;
	}
	if($student_playphone==0){
		$result['student_playphone']=0;
	}else{
		$result['student_playphone']=$student_playphone;
	}

	$result['havequestionTwo']=$havequestionTwo;
	$result['havequestionThree']=$havequestionThree;
	$result['advice']=$advice;
	$result['table1show']=$table1show;
	$result['result']=true;
// }else{
// 	$result['result']=false;
// }
		//二级单位督导		
	//人数
	$count1['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::UnitSupervisor[XPHEnum::Value],WebRole::UnitSupervisor[XPHEnum::Value]));
	$count1['groupby']='db_attend.listen_id';
	$count1['items']='count(*) count';
	$count1['join']=array('db_admin','db_admin.id=db_attend.listen_id');
	$CountSchoolSupervisor1=$this -> Attend_model -> get_list_full($count1);
	if($CountSchoolSupervisor1){
		$result['CountSchoolSupervisor1']=$CountSchoolSupervisor1[0]['count'];			
	}else{
		$result['CountSchoolSupervisor1']=0;
	}

	//听课次数
	$count1['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::UnitSupervisor[XPHEnum::Value],WebRole::UnitSupervisor[XPHEnum::Value]));
	$count1['items']='count(*) count';
	$count1['join']=array('db_admin','db_admin.id=db_attend.listen_id');
	$CountAttend1=$this -> Attend_model -> get_list_full($count1);
	if($CountAttend1){
		$result['CountSchoolSupervisorSum1']=$CountAttend1[0]['count'];	
	}else{
		$result['CountSchoolSupervisorSum1']=0;
	}			
//被听课总人平均分（教学水平+教学效果）
	$connar1['items']='sum(teaching_level_score)+sum(teaching_effect_score) total_sum';
	$connar1['join']=array('db_admin','db_admin.id=db_attend.listen_id');
	$connar1['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::UnitSupervisor[XPHEnum::Value],WebRole::UnitSupervisor[XPHEnum::Value]));			
	$connar1['groupby']='db_attend.id';
	$data1=$this -> Attend_model ->get_list_full($connar1);

	$count1=0;
	$teaching_level_score_sum1=0;
	$teaching_level_A1=0;
	$teaching_level_B1=0;
	$teaching_effect_score_sum1=0;
	$teaching_effect_A1=0;
	$teaching_effect_B1=0;
	$count1=0;
	$sum_avg=0;

	foreach ($data1 as $k1 => $v1) {
		$count1++;
		$sum_avg=$sum_avg+$v1['total_sum'];
	}
	if($sum_avg==0 || $count1==0){
		$result['total_avg']=0;
	}else{
		$result['total_avg']=sprintf("%.2f",($sum_avg/($count1*2)));
	}

		// //被听课人数		
		// $connar2['items']='count(*)  count';
		// $connar2['join']=array('db_admin','db_admin.id=db_attend.listen_id');
		// $connar2['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::UnitSupervisor[XPHEnum::Value],WebRole::UnitSupervisor[XPHEnum::Value]));			
		// $connar2['groupby']='db_attend.teacher_name';
		// $data2=$this -> Attend_model ->get_list_full($connar2);
		// if($data2){
		// 	$result['listend_sum']=$data2[0]['count'];			
		// }else{
		// 	$result['listend_sum']=0;
		// }

		//被听课人平均分	
	$result['listend_sum']=0;
	$result['UnitSupervisor_Minavg']=101;
	$result['UnitSupervisor_B']=0;
	$result['UnitSupervisor_A']=0;
	$result['UnitSupervisor_S']=0;
	$result['UnitSupervisor_C']=0;
	$connar3['items']='sum(teaching_level_score)+sum(teaching_effect_score) total_sum,db_attend.dept_name,db_attend.teacher_name';
	$connar3['join']=array('db_admin','db_admin.username=db_attend.teacher_name');
	$connar3['where']=$this ->sqlEscape('db_attend.status<>?? and db_attend.created>?? and db_attend.created<?? and (db_admin.role_id=?? or find_in_set(??,sub_role_id))',array(AttendStatus::Deleted[XPHEnum::Value],strtotime($start_time),strtotime($end_time),WebRole::UnitSupervisor[XPHEnum::Value],WebRole::UnitSupervisor[XPHEnum::Value]));			
	$connar3['groupby']='db_attend.teacher_name';

	$sql1="SELECT avg(total_sum/2) avg_teacher_score,teacher_name,dept_name  from(
	SELECT sum(teaching_level_score)+sum(teaching_effect_score) total_sum, db_attend.dept_name, db_attend.teacher_name FROM db_attend 
	LEFT JOIN db_admin a1 ON  a1 . username = db_attend . teacher_name  
	LEFT JOIN db_admin a2 ON  a2.id=db_attend.listen_id
	WHERE  db_attend . status  <> ".AttendStatus::Deleted[XPHEnum::Value]." and  db_attend . created  > ".strtotime($start_time)." and  db_attend . created  < ".strtotime($end_time)." 	and ( a2 . role_id  = ".WebRole::UnitSupervisor[XPHEnum::Value]." or find_in_set(".WebRole::UnitSupervisor[XPHEnum::Value].",a2.sub_role_id)) GROUP BY  db_attend . id 	) x GROUP BY teacher_name";
	$data3=$this -> Attend_model ->query($sql1);

		// $data3=$this -> Attend_model ->get_list_full($connar3);
	foreach ($data3 as $k1 => $v1) {
		$result['listend_sum']++;		
		if(($v1['avg_teacher_score'])<90){
			$result['UnitSupervisor_B']++;
		}
		if(($v1['avg_teacher_score'])<$result['UnitSupervisor_Minavg']){
			$result['UnitSupervisor_Minavg']=sprintf("%.2f",$v1['avg_teacher_score']);
			$result['UnitSupervisor_Mindept']=$v1['dept_name'];
			$result['UnitSupervisor_Minteacher']=$v1['teacher_name'];
		}
		if(($v1['avg_teacher_score'])>95){
			$result['UnitSupervisor_S']++;
		}
		if(($v1['avg_teacher_score'])>=90){
			$result['UnitSupervisor_A']++;
		}
		if(($v1['avg_teacher_score'])<85){
			$result['UnitSupervisor_C']++;
		}
	}
	if($result['UnitSupervisor_B']==0 || $result['listend_sum']==0){
		$result['UnitSupervisor_Bpercent']=0;
	}else{
		$result['UnitSupervisor_Bpercent']=sprintf("%.2f",($result['UnitSupervisor_B']/$result['listend_sum']))*100;
	}

	if($result['UnitSupervisor_S']==0 || $result['listend_sum']==0){
		$result['UnitSupervisor_Spercent']=0;
	}else{
		$result['UnitSupervisor_Spercent']=sprintf("%.2f",($result['UnitSupervisor_S']/$result['listend_sum']))*100;
	}

	if($result['UnitSupervisor_A']==0 || $result['listend_sum']==0){
		$result['UnitSupervisor_Apercent']=0;
	}else{
		$result['UnitSupervisor_Apercent']=sprintf("%.2f",($result['UnitSupervisor_A']/$result['listend_sum']))*100;
	}

	if($result['UnitSupervisor_C']==0 || $result['listend_sum']==0){
		$result['UnitSupervisor_Cpercent']=0;
	}else{
		$result['UnitSupervisor_Cpercent']=sprintf("%.2f",($result['UnitSupervisor_C']/$result['listend_sum']))*100;
	}
	if(!isset($result['UnitSupervisor_Mindept'])){
		$result['UnitSupervisor_Mindept']='';
	}
	if(!isset($result['UnitSupervisor_Minteacher'])){
		$result['UnitSupervisor_Minteacher']='';
	}	
		//平均分90以下人数最多分院
	$sql2="SELECT max(count_dept),dept_name from (SELECT count(dept_name) count_dept,dept_name from (SELECT avg(total_sum/2) avg_teacher_score,teacher_name,dept_name from(	SELECT sum(teaching_level_score)+sum(teaching_effect_score) total_sum,   db_attend  .  dept_name ,db_attend . teacher_name FROM db_attend  LEFT JOIN db_admin  ON  db_admin . username = db_attend . teacher_name   
	WHERE db_attend. status <> ".AttendStatus::Deleted[XPHEnum::Value]." and  db_attend .created >".strtotime($start_time)." and  db_attend.created< ".strtotime($end_time)." and (db_admin.role_id  = ".WebRole::UnitSupervisor[XPHEnum::Value]." or find_in_set(".WebRole::UnitSupervisor[XPHEnum::Value].",sub_role_id)) GROUP BY db_attend.id ) avg_score  GROUP BY teacher_name having avg_teacher_score<90) count_dept GROUP BY dept_name) max_dept";
	$data4=$this -> Attend_model -> query($sql2);
	if(isset($data4)){
		$result['downdetp']=$data4[0]['dept_name'];
	}else{
		$result['downdetp']=0;
	}

		//平均分95以上人数最多分院
	$sql3="SELECT max(count_dept),dept_name from (SELECT count(dept_name) count_dept,dept_name from (SELECT avg(total_sum/2) avg_teacher_score,teacher_name,dept_name from(	SELECT sum(teaching_level_score)+sum(teaching_effect_score) total_sum,   db_attend  .  dept_name ,db_attend . teacher_name FROM db_attend  LEFT JOIN db_admin  ON  db_admin . username = db_attend . teacher_name   
	WHERE db_attend. status <> ".AttendStatus::Deleted[XPHEnum::Value]." and  db_attend .created >".strtotime($start_time)." and  db_attend.created< ".strtotime($end_time)." and (db_admin.role_id  = ".WebRole::UnitSupervisor[XPHEnum::Value]." or find_in_set(".WebRole::UnitSupervisor[XPHEnum::Value].",sub_role_id)) GROUP BY db_attend.id ) avg_score  GROUP BY teacher_name having avg_teacher_score>95) count_dept GROUP BY dept_name) max_dept";
	$data5=$this -> Attend_model -> query($sql3);
	if(isset($data5)){
		$result['Updetp']=$data5[0]['dept_name'];
	}else{
		$result['Updetp']=0;
	}
		// 最高分院平均分
	$sql4="SELECT max(avg_teacher_score),dept_name from(SELECT avg(total_sum/2) avg_teacher_score,teacher_name,dept_name from(	SELECT sum(teaching_level_score)+sum(teaching_effect_score) total_sum,   db_attend . dept_name ,db_attend.teacher_name FROM db_attend  LEFT JOIN db_admin ON  db_admin . username = db_attend . teacher_name WHERE db_attend. status <> ".AttendStatus::Deleted[XPHEnum::Value]." and  db_attend .created >".strtotime($start_time)." and  db_attend.created< ".strtotime($end_time)." and (db_admin.role_id  = ".WebRole::UnitSupervisor[XPHEnum::Value]." or find_in_set(".WebRole::UnitSupervisor[XPHEnum::Value].",sub_role_id)) GROUP BY db_attend.id ) avg_score  GROUP BY dept_name ) max_avg_score";
	$data6=$this -> Attend_model -> query($sql4);
	if(isset($data6)){
		$result['max_avg_dept']=$data6[0]['dept_name'];
	}else{
		$result['max_avg_dept']='';
	}
	if($result['UnitSupervisor_Minavg']=101){
		$result['UnitSupervisor_Minavg']=0;
	}
	if($result['table1show']!=''){
		$op1= '中除了'.$table1show.'，';
	}else{
		$op1="";
	}
	if($result['havequestionTwo']){
		$op2= '但也有以下问题： ';
	}else{
		$op2="";
	}
	if($result['havequestionThree']){
		$op3= '但也有以下问题： ';
	}else{
		$op3="";
	}
	if($result['student_sleep']){
		$op4='个别课堂上有学生低头睡觉；';
	}else{
		$op4="";
	}
	if($student_lateorleave){
		$op5= '个别课堂上有学生迟到、早退；';
	}else{
		$op5="";
	}
	if($result['student_playphone']){
		$op6= '课堂上学生玩手机现象仍普遍出现。';
	}else{
		$op6="";
	}
	if($result['advice']!=''){
		$op7= $advice;
	}else{
		$op7="";
	}
	$count=$result['unCourseware']+$result['unHandout'];

	$data="<div class='content'>
	<div>
	<h3>（一）".$result['start_time']."至".$result['end_time']."校督导听课情况 </h3>
	<h4>1.整体评价情况</h4>
	".$result['start_time']."至".$result['end_time']."，".$result['CountSchoolSupervisor']."名校督导".$op1."督导听课共".$result['CountSchoolSupervisorSum']."次。教学水平总体评价平均".$result['teaching_level_score_avg']."分，90分及以上".$result['teaching_level_A']."人，占".$result['teaching_level_Aavg']."%，80分以下".$result['teaching_level_B']."人，占".$result['teaching_level_Bavg']."%；教学效果总体评价平均". $result['teaching_effect_score_avg']."分，90分及以上".$result['teaching_effect_A']."人，占".$result['teaching_effect_Aavg']."%，80分以下".$result['teaching_effect_B']."人，占". $result['teaching_effect_Bavg']."%；
	<h4>2.教师教学准备、开展情况 </h4>
	被校督导听课的教师整体较好，教师无迟到或早退".$result['noLateEarly']."人，教学资料不齐全".$count."人（其中无". TeachingReadiness::Fifth[XPHEnum::Caption]."的".$result['unCourseware']."人，无".TeachingReadiness::Sixth[XPHEnum::Caption]."的". $result['unHandout']."人），教学进度与授课计划基本保持一致，教师都能站姿教学，便于掌握学生上课情况，教师都有适当的互动，课堂环境卫生情况整体较好，课堂设施设备完好。".$op2."无板书".$result['noblackboard']."人；坐姿为主教学". $result['siteteaching']."人；
	<h3>3.学生常态</h3>
	本周期校督导听课，学生整体按时到课率普遍较高，课堂较有秩序。".$op3.$op4.$op5.$op6."
	<h3>4.听课意见与建议</h3>".$op7."
	</div>

	<div>
	<h3>（二）".$result['start_time'].'至'.$result['end_time']."各分院（部）督导听课情况</h3>
	<h4>1.".$result['start_time'].'至'.$result['end_time']."听课整体情况</h4>
	". $result['downdetp']."分院的老师比较多）最低分". $result['UnitSupervisor_Minavg']."分（". $result['UnitSupervisor_Mindept']."分院". $result['UnitSupervisor_Minteacher']."老师），95分以上有". $result['UnitSupervisor_S']."人占". $result['UnitSupervisor_Spercent']."% （". $result['Updetp']."分院的比较多）。 
	<h4>2.".$result['start_time'].'至'.$result['end_time']."督导听课成绩分析 </h4>
	各分院".$result['start_time'].'至'.$result['end_time'].
	"累计听课共". $result['listend_sum']."人，". $result['CountSchoolSupervisorSum1']."人次，平均分". $result['total_avg']."。". $result['UnitSupervisor_A']."位老师（". $result['UnitSupervisor_Apercent']."%）成绩在90分以上，". $result['UnitSupervisor_C']."人（". $result['UnitSupervisor_Cpercent']."%）老师成绩在85分以下。从各分院的听课情况看，". $result['max_avg_dept']."分院分值整体比较高。

	</div>			
	</div>
	";

	if(!$isExport){
		echo $data;
		$this -> load -> view("admin/statisticsAttendExport",$params);
	}else{
		$this-> load ->library('PHPWord/PHPWord');
		$PHPWord = new PHPWord();  
		$section = $PHPWord->createSection();  
		$PHPWord->addFontStyle('rStyle', array('bold'=>true,'color'=>'000000','size'=>16));  
		$PHPWord->addParagraphStyle('pStyle', array('align'=>'center'));  
		$section->addText("听课表汇总【".$result['start_time']."至".$result['end_time']."】", 'rStyle', 'pStyle');  
		$section->addTextBreak(2);
		$PHPWord->addFontStyle('fStyle', array('bold'=>false,'color'=>'000000','size'=>10)); 
		$num=0; 			
		$PHPWord->addFontStyle('xtitle', array('bold'=>true,'color'=>'000000','size'=>12));  
		$PHPWord->addFontStyle('li_title', array('bold'=>false,'color'=>'000000','size'=>11)); 
		$PHPWord->addParagraphStyle('pfirstStyle', array('indentation' => array('firstLine' => 460), 'lineHeight' => 1.0, 'spacing' => 120));
		$section->addText("（一）".$result['start_time']."至".$result['end_time']."校督导听课情况", 'xtitle');
		$section->addTextBreak(1);
		$section->addText("1.整体评价情况", 'li_title');
		$section->addTextBreak(1);
		$section->addText($result['start_time']."至".$result['end_time']."，".$result['CountSchoolSupervisor']."名校督导".$op1."督导听课共".$result['CountSchoolSupervisorSum']."次。教学水平总体评价平均".$result['teaching_level_score_avg']."分，90分及以上".$result['teaching_level_A']."人，占".$result['teaching_level_Aavg']."%，80分以下".$result['teaching_level_B']."人，占".$result['teaching_level_Bavg']."%；教学效果总体评价平均". $result['teaching_effect_score_avg']."分，90分及以上".$result['teaching_effect_A']."人，占".$result['teaching_effect_Aavg']."%，80分以下".$result['teaching_effect_B']."人，占". $result['teaching_effect_Bavg']."%", 'fStyle','pfirstStyle');
		$section->addText("2.教师教学准备、开展情况", 'li_title');
		$section->addTextBreak(1);
		$section->addText("被校督导听课的教师整体较好，教师无迟到或早退".$result['noLateEarly']."人，教学资料不齐全".$count."人（其中无". TeachingReadiness::Fifth[XPHEnum::Caption]."的".$result['unCourseware']."人，无".TeachingReadiness::Sixth[XPHEnum::Caption]."的". $result['unHandout']."人），教学进度与授课计划基本保持一致，教师都能站姿教学，便于掌握学生上课情况，教师都有适当的互动，课堂环境卫生情况整体较好，课堂设施设备完好。".$op2."无板书".$result['noblackboard']."人；坐姿为主教学". $result['siteteaching']."人", 'fStyle','pfirstStyle');
		$section->addTextBreak(1);
		$section->addText("3.学生常态", 'li_title');
		$section->addTextBreak(1);
		$section->addText("本周期校督导听课，学生整体按时到课率普遍较高，课堂较有秩序。".$op3.$op4.$op5.$op6, 'fStyle','pfirstStyle');
		$section->addTextBreak(1);
		$section->addText("4.听课意见与建议", 'li_title');
		$section->addTextBreak(1);
		foreach ($array_advice as $k => $v) {
			$num=$k+1;
			$section->addText("   ".$num.".".$v, 'fStyle');
		}
		$section->addTextBreak(2);
		$section->addText("（二）".$result['start_time']."至".$result['end_time']."各分院（部）督导听课情况", 'xtitle');
		$section->addTextBreak(1);
		$section->addText("1.".$result['start_time']."至".$result['end_time']."听课整体情况", 'li_title');
		$section->addTextBreak(1);
		$section->addText( $result['downdetp']."分院的老师比较多）最低分". $result['UnitSupervisor_Minavg']."分（". $result['UnitSupervisor_Mindept']."分院". $result['UnitSupervisor_Minteacher']."老师），95分以上有". $result['UnitSupervisor_S']."人占". $result['UnitSupervisor_Spercent']."% （". $result['Updetp']."分院的比较多）。", 'fStyle','pfirstStyle');
		$section->addTextBreak(1);
		$section->addText("2.".$result['start_time']."至".$result['end_time']."督导听课成绩分析", 'li_title');
		$section->addTextBreak(1);
		$section->addText("各分院".$result['start_time'].'至'.$result['end_time'].
			"累计听课共". $result['listend_sum']."人，". $result['CountSchoolSupervisorSum1']."人次，平均分". $result['total_avg']."。". $result['UnitSupervisor_A']."位老师（". $result['UnitSupervisor_Apercent']."%）成绩在90分以上，". $result['UnitSupervisor_C']."人（". $result['UnitSupervisor_Cpercent']."%）老师成绩在85分以下。从各分院的听课情况看，". $result['max_avg_dept']."分院分值整体比较高。", 'fStyle','pfirstStyle');


		$write = new PHPWord_Writer_Word2007($PHPWord); 
		$director = "upload/export/" . date('Ymd', time()) . "/";
		if (!file_exists($director)) {
	            //检查是否有该文件夹，如果没有就创建，并给予最高权限
			mkdir($director, 0777);
		}        
		$file_name ='听课表汇总'.date('Ymd').'.docx';       	
		$write->save($director.iconv('utf-8', 'gb2312', $file_name));
		exit(retJson('返回地址',true,$director.$file_name));
	}

}


}



